package com.example.wanbaqian.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;

import com.example.wanbaqian.R;
import com.example.wanbaqian.bean.MessageListBean;
import com.example.wanbaqian.customView.swipeLayout.SwipeDeleteCallback;
import com.example.wanbaqian.customView.swipeLayout.SwipeLayout;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/4/13 0013.
 * 消息列表适配器
 */

public class MessageListAdapter extends CommonAdapter<MessageListBean> {
    private SwipeDeleteCallback callback;
    private static final String TAG = "MessageListAdapter";

    public MessageListAdapter(Context context, int layoutId, List<MessageListBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, MessageListBean messageListBean, final int position) {
        Log.i(TAG, "convert: " + position);
        holder.setText(R.id.item_meeageTitle, messageListBean.getMessage_title());
        holder.setText(R.id.item_meeageTime, messageListBean.getMessage_time());
        holder.setText(R.id.item_meeageContent, messageListBean.getMessage_content());
        holder.setVisible(R.id.item_meeageStat, messageListBean.getMessage_status().equals("0"));
        SwipeLayout swipeLayout = holder.getView(R.id.swipelayout);
        swipeLayout.getDeleteView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callback.deleteListeren(position);
            }
        });
    }

    public void setDeleteCallBack(SwipeDeleteCallback callback) {
        this.callback = callback;
    }
}
